﻿
Partial Class WebForm_ManageTrainingRegister_QueryTrainingList
    Inherits My.MyUserControl

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            Me.BindDDLOrg()
        End If
    End Sub
    'Protected Sub UploadFileControl1_Uploaded(ByVal sender As Object, ByVal e As WebForm_CommonControl_UploadFileControl.UploadedEventArgs) Handles UploadFileControl1.Uploaded
    '    Me.BindGV()
    'End Sub
    'Protected Overrides Sub Render(ByVal writer As HtmlTextWriter)
    '    MyBase.Render(writer)
    '    Me.Page.ClientScript.RegisterForEventValidation(ddlOrg.ClientID)

    'End Sub
    Protected Sub btnQuery_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnQuery.Click

        Me.BindGV()

    End Sub
    Protected Sub gv_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles gv.PageIndexChanging
        Me.gv.PageIndex = e.NewPageIndex
        Me.BindGV()
    End Sub
    Protected Sub gv_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles gv.RowCommand
        If e.CommandName = "Upload" Then

            Dim row As GridViewRow = TryCast(TryCast(e.CommandSource, Control).NamingContainer, GridViewRow)
            Dim key As DataKey = gv.DataKeys(row.RowIndex)
            Me.UploadFileControl1.strType = e.CommandArgument
            Me.UploadFileControl1.IsColse = True

            '環保局人員及區清潔隊爲承辦單位時可以上傳檔案刪除檔案,否則一般志工隊幹部及區清潔隊只能下載檔案
            If CanAdmin = True Then
                Me.UploadFileControl1.IsAdmin = True
            Else

                If CanEdit = True Then
                    If clsAuth.OrganizationName = key("OrganizationName") Then
                        Me.UploadFileControl1.IsAdmin = True
                    Else
                        Me.UploadFileControl1.IsAdmin = False
                    End If
                ElseIf CanQuery = True Then
                    Me.UploadFileControl1.IsVolunteerLeader = True
                End If

            End If
            Me.UploadFileControl1.InitDataAndShow()
        End If
    End Sub
    Private Sub BindDDLOrg()
    
    

        Me.ddlOrg.DataTextField = "OrganizationName"
        Me.ddlOrg.DataValueField = "UOrganizationID"
        Me.ddlOrg.DataSource = MyObj.GetDDLDirectOrganizationData()
        Me.ddlOrg.DataBind()
        Me.ddlOrg.Items.Insert(0, MyObj.GetDDLSelectAllItem())
    End Sub
    Public Sub BindGV()
        Dim sql As New MyStringBuilder
        Dim dat As New clsData

        sql.Length = 0
        sql.AppendFormat("SELECT distinct A.Id, A.GroupName , o.OrganizationName, A.StartDate,U.FileSavePath,Case when (U.FileShortName)<>'' then '已上傳' else '' end as IsUpload  ")
        sql.AppendFormat("FROM TrainingCourseGroup A ")
        sql.AppendFormat("inner join CodeMapping B on A.GroupType=B.Value ")
        sql.AppendFormat("and B.TableName  ='TrainingCourseGroup' AND B.ColumnName='GroupType' ")
        sql.AppendFormat("left join UploadFiles U on A.ID=U.theType AND theClass='TrainingRecord' ")
        sql.AppendFormat("inner join OrganizationView o on  A.UOrganizationID=o.UOrganizationID ")
        sql.AppendFormat("where 1=1 ")
        sql.AppendFormat(" and  A.StartDate>='{0:yyyy/MM/dd}'", Me.txtStartDate.Value)


        sql.AppendFormat(" and  A.StartDate<=DateAdd(dd,1,'{0:yyyy/MM/dd}')", Me.txtEndDate.Value)

        If ddlOrg.SelectedValue <> "" Then
            sql.AppendFormat("and A.UOrganizationID ='{0}' ", ddlOrg.SelectedValue)
        End If
        sql.AppendFormat("order by A.StartDate ")
        DT = dat.GetData(sql)

        gv.DataSource = DT
        gv.DataBind()
    End Sub
 
    Public Property DT() As Data.DataTable
        Get
            Return ViewState("DT")
        End Get
        Set(ByVal value As Data.DataTable)
            ViewState("DT") = value
        End Set
    End Property


End Class
